feat(import/extensions): allow enforcement decision overrides based on specifier #3105
+165
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I already use
import/order
with custompathGroups
. This allows me to control the grouping of certain paths, such as custom aliases fromtsconfig.json
'spaths
. This in turn ensures all imports are sorted properly, even when the project is using syntactically sound but otherwise bespoke custom aliases likemy-project:api.js
(in lieu of../../../../src/api.js
).Unfortunately, if I mistype
my-project:api
(i.e. I forgot the extension), theimport/extensions
rule will still pass; the enforcement decision is "ignore" when it should have been "enforce". This is because, likeimport/order
, the grouping strategy employed by this rule is quite coarse-grained, but unlikeimport/order
, this rule is missing apathGroups
-like setting for finer-grained sorting. The goal of this PR is to fill that gap.This PR allows developers to override the decision to enforce or ignore extensions for imports with matching specifiers. This is implemented via
pathGroupOverrides
.The documentation updates associated with the changes in this PR are part of a separate PR and can be previewed here (towards the bottom of the section). This PR also includes tests.